cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
cmake_policy(SET CMP0054 NEW)

set(PROJECT_VERSION 0.2.0)
project(SV2CameraCppNodes VERSION ${PROJECT_VERSION} LANGUAGES CXX)

add_definitions(-DAPI_EXPORTS)
set(CMAKE_BUILD_TYPE "Release")

## JETSON, X86_CUDA, X86_INTEL
message(STATUS "System:${CMAKE_HOST_SYSTEM_PROCESSOR}")
if(NOT DEFINED PLATFORM)
  message(FATAL_ERROR "PLATFORM NOT SPECIFIED!")
else()
  message(STATUS "PLATFORM: ${PLATFORM}")
  if(PLATFORM STREQUAL "JETSON")
    add_definitions(-DPLATFORM_JETSON)
  elseif(PLATFORM STREQUAL "X86_CUDA")
    add_definitions(-DPLATFORM_X86_CUDA)
  elseif(PLATFORM STREQUAL "X86_INTEL")
    add_definitions(-DPLATFORM_X86_INTEL)
  elseif(PLATFORM STREQUAL "ROCKCHIP")
    add_definitions(-DPLATFORM_ROCKCHIP)
  else()
    message(FATAL_ERROR "UNSUPPORTED PLATFORM!")
  endif()
endif()


add_definitions(-DWITH_GSTREAMER)
find_package(SpireMS REQUIRED)
find_package(OpenCV 4 REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")


include_directories(${SpireMS_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(
  ${CMAKE_CURRENT_SOURCE_DIR}/include
  ${CMAKE_CURRENT_SOURCE_DIR}/include/rga
  ${CMAKE_CURRENT_SOURCE_DIR}/include/alloc_dma
)


include_directories(${CMAKE_CURRENT_SOURCE_DIR}/video_io/gstreamer)
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
  include_directories(
    "/usr/include/gstreamer-1.0"
    "/usr/local/include/gstreamer-1.0"
    "/usr/include/glib-2.0"
    "/usr/lib/aarch64-linux-gnu/glib-2.0/include"
  )
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
  include_directories(
    "/usr/include/gstreamer-1.0"
    "/usr/local/include/gstreamer-1.0"
    "/usr/include/glib-2.0"
    "/usr/lib/x86_64-linux-gnu/glib-2.0/include"
  )
endif()

file(GLOB_RECURSE LIBSO 
  ${PROJECT_SOURCE_DIR}/lib/*.so
)
# Public header
set(HEADS
  include/sv2_camera_base.h
  include/sv2_camera_node.h
)

file(GLOB_RECURSE SRCS 
  ${PROJECT_SOURCE_DIR}/src/*.cpp
)


# Demo
add_executable(MIPICameraCppNode_Rknn camera_reading_demo.cpp ${SRCS})
link_directories(
  ${PROJECT_SOURCE_DIR}/lib
)
target_link_libraries(MIPICameraCppNode_Rknn ${OpenCV_LIBS} ${SpireMS_LIBS} ${LIBSO} -lpthread)


install(TARGETS MIPICameraCppNode_Rknn
  RUNTIME DESTINATION bin
)
